export default function combineReducer(reducers) {
  

  /* 例如 reducerKeys = ['counter', 'info'] */
  const reducerKeys = Object.keys(reducers)

  /**
   * 合并 counterReducer/inofReducer
   */
  return function combination(state={}, action) {
    const nextState = {} // 新 state

    //遍历reducer组，生成新的state

    for(let i=0;i<reducerKeys.length;i++) {
      const key = reducerKeys[i]
      const reducer = reducers[key]

      const previousStateForKey = state[key] // 旧 state key

      const nextStateForKey = reducer(previousStateForKey, action) // 新 state 

      nextState[key] = nextStateForKey
    }
    return nextState
  }
}